package net.xconcepts.stockdata.model.analysis;

import java.util.HashMap;
import java.util.Map;

import net.xconcepts.stockdata.model.analysis.indicator.Indicator;
import net.xconcepts.stockdata.model.analysis.symbol.Symbol;
import net.xconcepts.stockdata.model.tick.SymbolTick;

public class NumericRule extends Rule<Double> {

	public final double min;
	public final double max;
	
	
	public NumericRule(Indicator<Double, ?> indicator, double min, double max) {
		super(indicator);
		this.min = min;
		this.max = max;
	}
	
	/**
	 * 
	 * @param indicator
	 * @param threshold
	 * @param greaterThan true if should be greater than
	 */
	public NumericRule(Indicator<Double, ?> indicator, double threshold, boolean greaterThan) {
		super(indicator);
		this.min = greaterThan ? threshold : Double.MIN_VALUE;
		this.max = greaterThan ? Double.MAX_VALUE : threshold;
	}

	@Override
	public Map<Symbol, Boolean> processTicks(Map<Symbol, SymbolTick> ticks) {
		Map<Symbol, Double> indicatorResults = getIndicator().processTicks(ticks);
		Map<Symbol, Boolean> ruleResults = new HashMap<Symbol, Boolean>();
		
		for(Symbol symbol : indicatorResults.keySet()) {
			Double result = indicatorResults.get(symbol);
			ruleResults.put(symbol, (min < result && max > result));
		}
		
		return ruleResults;
	}

}
